/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.							  */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
/*----------------------------------------------------------------------------*/
#ifndef DIGITAL_MODULE_H_
#define DIGITAL_MODULE_H_

#include "Module.h"
#include "ChipObject.h"

class I2C;

const unsigned kExpectedLoopTiming = 261;

class DigitalModule: public Module
{
	friend class I2C;

protected:
   DigitalModule(unsigned slot);
   virtual ~DigitalModule();

public:
	void SetPWM(unsigned channel, unsigned char value);
	unsigned char GetPWM(unsigned channel);
	void SetPWMPeriodScale(unsigned channel, unsigned squelchMask);
	void SetRelayForward(unsigned channel, bool on);
	void SetRelayReverse(unsigned channel, bool on);
	bool AllocateDIO(unsigned channel, bool input);
	void FreeDIO(unsigned channel);
	void SetDIO(unsigned channel, short value);
	unsigned GetDIO(unsigned channel);
	void Pulse(unsigned channel, unsigned char pulseLength);
   bool IsPulsing(unsigned channel);
   bool IsPulsing(void);

   I2C* GetI2C(unsigned address);

	static unsigned SlotToIndex(unsigned slot);
   static DigitalModule* GetInstance(unsigned slot);
	static unsigned char RemapDigitalChannel(unsigned channel) { return 15 - channel; }; // TODO: Need channel validation
	static unsigned char UnmapDigitalChannel(unsigned channel) { return 15 - channel; }; // TODO: Need channel validation

private:
   tDIO *m_fpgaDIO;
};

#endif

